package hw1.package1.space;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class AddCity extends Activity implements View.OnClickListener{


    Button add, cancel;
    EditText edit;
    
    @Override
    public void onCreate (Bundle savedInstanceBundle){
    	super.onCreate (savedInstanceBundle);
        setContentView (R.layout.adding);
  
        add=(Button)findViewById(R.id.addB);
        cancel=(Button)findViewById(R.id.cancelB);
        edit=(EditText)findViewById(R.id.editC);

        add.setOnClickListener(this);
        cancel.setOnClickListener(this);
    }

	public void onClick(View v) {        
		if(v==add){                          //when the user presses the Add button to add a new city to the list
			Intent intent=getIntent();      
			intent.putExtra("nume", edit.getText().toString()); //deliver the name of the city to the initial activity
			setResult(1,intent);                 //setting the result code 1            
			finish();                   //and finish the current activity
		}
		if(v==cancel){                   //if the user presses Cancel
			Intent intent=getIntent();
			setResult(0,intent);         //set the result code 0  
			finish();                    //and finish the current activity
		}
		
	}
}
